<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>View Sale Lead | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <p:panel id="panel" header="View Sale Leads">
            <h:form>
            <p:dataTable var="saleLead" value="#{saleLeadDataTableBean.saleLeads}" 
                         dynamic="true" paginator="true" rows="5" emptyMessage="No sale lead found in database." 
                         selection="#{saleLeadDataTableBean.selectedSaleLead}" onRowSelectUpdate="display"> 

                        <p:column selectionMode="single" />

                        <p:column sortBy="#{saleLead.saleLeadName}" filterBy="#{saleLead.saleLeadName}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Company Name:" /> 
                            </f:facet> 
                            <h:outputText value="#{saleLead.saleLeadName}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleLead.registrationNumber}" filterBy="#{saleLead.registrationNumber}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Registration Number:" /> 
                            </f:facet> 
                            <h:outputText value="#{saleLead.registrationNumber}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleLead.saleLeadAddress}" filterBy="#{saleLead.saleLeadAddress}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Address" /> 
                            </f:facet> 
                            <h:outputText value="#{saleLead.saleLeadAddress}" /> 
                        </p:column>

                        <p:column sortBy="#{saleLead.customerType}" filterBy="#{saleLead.customerType}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Customer Type" /> 
                            </f:facet> 
                            <h:outputText value="#{saleLead.customerType}" /> 
                        </p:column>

                        <f:facet name="footer">  
                            <p:commandButton value="View" image="ui-icon ui-icon-search" onclick="viewSaleLead.show()" update="display1 repTable"/>     
                            <p:commandButton value="Edit" image="ui-icon ui-icon-pencil" actionListener="#{saleLeadDataTableBean.editSaleLead}"/>     
                            <p:growl id="messages" />
                            <p:menuButton value="Other Options">
                                <p:menuitem value="Add New Sale Inquiry" update="messages" actionListener="#{saleLeadDataTableBean.addSaleInquiry}"/>
                                <p:menuitem value="Add New Sale Quotation" update ="messages" actionListener="#{saleLeadDataTableBean.addSaleQuotation}"/>
                                <p:menuitem value="View Sale Inquiries" update = "messages" actionListener="#{saleLeadDataTableBean.viewSaleInquiries}" />
                                <p:menuitem value="View Sale Quotation" update = "messages" actionListener="#{saleLeadDataTableBean.viewSaleQuotations}" />
                                </p:menuButton>
                        </f:facet>
            </p:dataTable>
                

            </h:form>
            
            <h:form id="form1" prependId="false">
                <p:dialog header="Sale lead Details" widgetVar="viewSaleLead" width="700">
                    
                    <p:fieldset legend="Company Details" style="font-weight: bold">
                    <h:panelGrid columns="3" cellpadding="10" id="display1"> 
                        <h:outputLabel for="saleLeadName" style="font-weight: bold" value="Company Name: " /> 
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.saleLeadName}" id="saleLeadName"/>
                        <p:message for="saleLeadName" /> 

                        <h:outputLabel for="registrationNumber" style="font-weight: bold" value="Registration Number: " /> 
                        <h:outputText value="#{saleLeadDataTableBean.selectedSaleLead.registrationNumber}" id="registrationNumber" />
                        <p:message for="registrationNumber" />  

                        <h:outputLabel for="address" style="font-weight: bold" value="Address: " /> 
                        <h:outputText id="address" value="#{saleLeadDataTableBean.selectedSaleLead.saleLeadAddress}"/>
                        <p:message for="address" /> 

                        <h:outputLabel for="customerType" style="font-weight: bold" value="Customer Type: " /> 
                        <h:outputText id ="customerType" value="#{saleLeadDataTableBean.selectedSaleLead.customerType}"/>

                        <p:message for="customerType" />

                    </h:panelGrid>     
                    </p:fieldset>
                    <br/>
                    <p:fieldset legend="Representative Details">
                        <p:dataTable value="#{saleLeadDataTableBean.selectedSaleLead.representatives}" var="rep" id="repTable">
                            <p:column sortBy="#{rep.name}" style="width: 30%">     
                                <f:facet name="header"> 
                                    <h:outputText value="Representative Name" /> 
                                </f:facet> 
                                <h:outputText value="#{rep.name}" /> 
                            </p:column>

                            <p:column sortBy="#{rep.email}" style="width: 40%"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Email" /> 
                                </f:facet> 
                                <h:outputText value="#{rep.email}" /> 
                            </p:column>

                            <p:column sortBy="#{rep.contactNumber}" style="width: 30%"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Contact Number" /> 
                                </f:facet> 
                                <h:outputText value="#{rep.contactNumber}" /> 
                            </p:column>
                        </p:dataTable>
                    </p:fieldset>
                </p:dialog> 
            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>
